package com.qch.demo;

import java.util.concurrent.BlockingQueue;

/**
 * @Author qch
 * @Date 2021/5/11
 */
public class Producer implements Runnable{
    private BlockingQueue <Kouzhao> queue;
    public Producer(BlockingQueue <Kouzhao> blockingQueue){
        this.queue=blockingQueue;
    }
    private Integer idex=0;
    public void run() {
        //生产内容
        while (true)
        {
            try {
                Thread.sleep(100);
                if(queue.remainingCapacity()<=0){
                    System.out.println("口罩堆积了");
                }else {
                Kouzhao kouzhao=new Kouzhao();
                kouzhao.setId(idex++);
                kouzhao.setType("N95");
                System.out.println("正在生产第："+(idex-1)+"号口罩");
                queue.put(kouzhao);
                System.out.println("已经生产了口罩："+queue.size()+"个");}
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }
    }
}
